package com.hdoit.ares.logical.share.dao.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.share.dao.IViewTimeDao;
import com.hdoit.ares.logical.share.mapper.ViewTimeMapper;
import com.hdoit.ares.logical.share.model.ViewTime;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      wangxuexue
 * @email       
 * @createtime  2017年11月22日 15:58:36
 * @comment
 */
@Component
public class ViewTimeDaoImpl extends SuperDao<ViewTime> implements IViewTimeDao{

	private ViewTimeMapper viewTimeMapper;
	
	public ViewTimeMapper getViewTimeMapper() {
		return viewTimeMapper;
	}

	@Resource(name = "viewTimeMapper")
	public void setViewTimeMapper(ViewTimeMapper viewTimeMapper) {
		this.viewTimeMapper = viewTimeMapper;
	}

	@Override
	public int updateViewTimeById(String shareId,String type) {
		
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.update(ViewTime.class)
						.addBody("SET `viewtimes`=`viewtimes`+1")
						.andEq("type",type)
						.andEq("shareid",shareId);
		
		return update(finderExpression);
		
	}

	@Override
	public ViewTime queryModelByShareId(String shareId,String type) {
		
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(ViewTime.class)
						.andEq("type",type)
						.andEq("shareid",shareId);
		
		return queryModel(finderExpression);
	}

}